class InputReader {

	import std.stdio, std.conv, std.string;
	
	private std.stdio.File input;
	private bool lastOne;
	private uint bufSize;
	private char[] buf;	
	private uint remainStart;
	private uint idx = 0;
	private char d;

	public this(std.stdio.File input = stdin, uint bufSize = 1000000, char separator = ' ') {
		this.input = input;
		this.bufSize = bufSize;
		this.d = separator;
		this.lastOne = false;
		this.buf = new char[bufSize];
		this.input.rawRead(this.buf);
		this.idx = 0;
		this.buf = reduce(this.buf);
		this.remainStart = lastIndexOf(this.buf, '\n');
	}

	private int first255(char[] ar) {
		int ans = -1;
		char term = to!char(255);
		for (int j = 0; j < ar.length; ++j)
			if (ar[j] == term)
				return j;
		return ans;
	}

	private char[] reduce(char[] ar) {
		auto termIndex = first255(ar);
		if (termIndex == 0) {
			this.lastOne = true;
			return null;
		}
		else if (termIndex == -1)
			return ar;
		else {
			this.lastOne = true;
			return ar[0 .. termIndex];
		}
	}

	private void refillBuf() {
		char[] newBuf = new char[bufSize];
		input.rawRead(newBuf);		
		if (remainStart == -1 || remainStart == bufSize - 1)
			buf ~= reduce(newBuf);
		else
			buf = buf[(remainStart + 1) .. buf.length] ~ reduce(newBuf);
		remainStart = lastIndexOf(buf, "\n");
		idx = 0;
	}

	public char[] next() {
		if ((idx >= remainStart) & !lastOne) 
			refillBuf();
		while (idx < buf.length && (buf[idx] == d || buf[idx] == '\n'))
			++idx;
		if ((idx >= remainStart) & !lastOne)
			refillBuf();		
		uint cnt = idx;
		while (cnt < buf.length && buf[cnt] != d && buf[cnt] != '\n')
			++cnt;		
		char[] ans = buf[idx .. cnt];
		idx = cnt;
		return ans;
	}

	public int nextInt() {
		return std.conv.to!int(strip(next()));
	}

	public long nextLong() {
		return std.conv.to!long(strip(next()));
	}

	public double nextDouble() {
		return std.conv.to!double(strip(next()));
	}

}